home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1453.dms / var1453.adf / AmigaDOS / Example7.c < prev    next >
C/C++ Source or Header  |  1992-05-02  |  5KB  |  149 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM System                  Amiga C Club       */
  7. /* Chapter: AmigaDOS                    Tulevagen 22       */
  8. /* File:    Example7.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-02                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This program takes a file/directory/device name as parameter, and */
  21. /* prints out some interesting information about it.                 */
  22.  
  23.  
  24. #include <libraries/dos.h>
  25. #include <exec/memory.h>
  26.  
  27.  
  28. main( argc, argv )
  29. int argc;
  30. char *argv[];
  31. {
  32.   struct FileLock *lock;
  33.   struct FileInfoBlock *fib_ptr; /* Declare a FileInfoBlock */
  34.                                  /* pointer called fib_ptr. */
  35.  
  36.  
  37.   if( argc < 2 )
  38.   {
  39.     /* No file/directory specified! */
  40.     printf("What file/directory do you actually want to examine?\n");
  41.     exit();
  42.   }
  43.  
  44.  
  45.  
  46.   /* 1. Allocate enough memory for a FileInfoBlock structure:       */
  47.   /* (Here is some casting again. AllocMem() returns a CPTR memory  */
  48.   /* pointer, while fib_ptr is a pointer to a FileInfoBlock. It is  */
  49.   /* actually the same thing, but to not make the compiler upset we */
  50.   /* tell it that AllocMem() returns a pointer to a FileInfoBlock.) */
  51.   fib_ptr = (struct FileInfoBlock *)
  52.             AllocMem( sizeof( struct FileInfoBlock ),
  53.                       MEMF_PUBLIC | MEMF_CLEAR );
  54.  
  55.   /* MEMF_PUBLIC: Any type of memory (chip/fast) */
  56.   /* MEMF_CLEAR:  Clear the allocated memory.    */
  57.  
  58.   /* Check if we have allocated the memory successfully: */
  59.   if( fib_ptr == NULL )
  60.   {
  61.     printf("Not enough memory!\n");
  62.     exit();
  63.   };
  64.  
  65.  
  66.   
  67.   /* 2. Try to lock the file: */
  68.   /* (Casting again! We tell the compiler that Lock() returns a pointer */
  69.   /* to a FileLock structure.)                                          */
  70.   lock = (struct FileLock *) Lock( argv[ 1 ], SHARED_LOCK );
  71.   
  72.   /* Colud we lock the file? */
  73.   if( lock == NULL )
  74.   {
  75.     printf("Could not lock the file/directory!\n");
  76.  
  77.     /* Deallocate the memory we have allocated: */
  78.     FreeMem( fib_ptr, sizeof( struct FileInfoBlock ) );
  79.     
  80.     exit();
  81.   }
  82.  
  83.  
  84.  
  85.   /* 3. Try to get some information about the file: */
  86.   if( Examine( lock, fib_ptr ) == NULL )
  87.   {
  88.     printf("Could not examine the file/directory!\n");
  89.  
  90.     /* Deallocate the memory we have allocated: */
  91.     FreeMem( fib_ptr, sizeof( struct FileInfoBlock ) );
  92.     
  93.     /* Unlock the file: */
  94.     UnLock( lock );  
  95.     
  96.     exit();
  97.   }
  98.  
  99.  
  100.  
  101.   /* 4. You may now examine the FileInfoBlock structure! */
  102.  
  103.   if( fib_ptr->fib_DirEntryType < 0 )
  104.     printf("Type:       File\n");
  105.   else
  106.     printf("Type:       Directory\n");
  107.  
  108.   printf("Name:       %s\n", fib_ptr->fib_FileName );
  109.   printf("Size:       %d\n", fib_ptr->fib_Size );
  110.   printf("Blocks:     %d\n", fib_ptr->fib_NumBlocks );
  111.   printf("Comment:    %s\n",
  112.     fib_ptr->fib_Comment[0] != '\0' ? fib_ptr->fib_Comment : "No comment" );
  113.  
  114.   printf("Deletable:  %s\n",
  115.     fib_ptr->fib_Protection & FIBF_DELETE ? "On" : "Off" );
  116.  
  117.   printf("Executable: %s\n",
  118.     fib_ptr->fib_Protection & FIBF_EXECUTE ? "On" : "Off" );
  119.  
  120.   printf("Writable:   %s\n",
  121.     fib_ptr->fib_Protection & FIBF_WRITE ? "On" : "Off" );
  122.  
  123.   printf("Readable:   %s\n",
  124.     fib_ptr->fib_Protection & FIBF_READ ? "On" : "Off" );
  125.  
  126.   printf("Archive:    %s\n",
  127.     fib_ptr->fib_Protection & FIBF_ARCHIVE ? "On" : "Off" );
  128.  
  129.   printf("Pure:       %s\n",
  130.     fib_ptr->fib_Protection & FIBF_PURE ? "On" : "Off" );
  131.  
  132.   printf("Script:     %s\n",
  133.     fib_ptr->fib_Protection & FIBF_SCRIPT ? "On" : "Off" );
  134.  
  135.   printf("Days:       %d\n", fib_ptr->fib_Date.ds_Days );
  136.   printf("Minutes:    %d\n", fib_ptr->fib_Date.ds_Minute );
  137.   printf("Ticks:      %d\n", fib_ptr->fib_Date.ds_Tick );
  138.  
  139.  
  140.  
  141.   /* 5. Unlock the file: */
  142.   UnLock( lock );  
  143.  
  144.  
  145.  
  146.   /* 6. Deallocate the memory we have allocated: */
  147.   FreeMem( fib_ptr, sizeof( struct FileInfoBlock ) );
  148. }
  149.